﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using NorthWin_Test.Entity;
using NorthWin_Test.Dao;

namespace NorthWin_Test.Biz
{
    public class UserBiz
    {
        public ArrayList GetAllUser()
        {
            ArrayList arr = new ArrayList();
            UserDao dao = new UserDao();
            DataTable table = dao.GetAllUser();
            arr = GetEntity(table);
            return arr;
        }

        public ArrayList GetEntity(DataTable table)
        {
            ArrayList arr = new ArrayList();
            foreach (DataRow row in table.Rows)
            {
                UserEntity en = new UserEntity();
                en.UserID = row["UserID"].ToString();
                en.UserName = row["UserName"].ToString();
                
                arr.Add(en);
            }

            return arr;
        }

        public int AddUser(UserEntity entity)
        {
            UserDao dao = new UserDao();
            int result = dao.AddUser(
                    entity.UserID,
                    entity.UserName
                );
            return result;
        }

        public int UpdateUser(UserEntity entity, string UserIDKey)
        {
            UserDao dao = new UserDao();
            int result = dao.UpdateUser(entity.UserID, entity.UserName, UserIDKey);
            return result;
        
        }

        public int DeleteUser(string UserIDKey)
        {
            UserDao dao = new UserDao();
            int result = dao.DeleteUser(UserIDKey);
            return result;
        }
    }
}
